package com.ruoyi.web.xxj.contoller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.xxj.domain.ClassOrder;
import com.ruoyi.web.xxj.domain.vo.ClassOrderVo;
import com.ruoyi.web.xxj.enums.PayStatus;
import com.ruoyi.web.xxj.service.IClassOrderService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程订单Controller
 *
 * @author ruoyi
 * @date 2024-01-25
 */
@Api(tags = "课程订单管理")
@RestController
@RequestMapping("/xxj/classOrder")
public class ClassOrderController extends BaseController {
    @Autowired
    private IClassOrderService classOrderService;

    /**
     * 查询课程订单列表
     */
    @ApiOperation("查询课程订单列表")
    @GetMapping("/list")
    public TableDataInfo<ClassOrderVo> list(ClassOrder classOrder) {
        startPage();
        List<ClassOrderVo> list = classOrderService.selectClassOrderList(classOrder);
        return getDataTable(list);
    }

    /**
     * 导出课程订单列表
     */
    @ApiOperation("导出课程订单列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassOrder classOrder) {
    	PageUtils.clearPage();
        List<ClassOrderVo> list = classOrderService.selectClassOrderList(classOrder);
        ExcelUtil<ClassOrderVo> util = new ExcelUtil<ClassOrderVo>(ClassOrderVo.class);
        util.exportExcel(response, list, "课程订单数据");
    }

    /**
     * 获取课程订单详细信息
     */
    @ApiOperation("获取课程订单详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(classOrderService.selectClassOrderById(id));
    }

    /**
     * 新增课程订单
     */
    @ApiOperation("新增课程订单")
    @PostMapping
    public AjaxResult add(@RequestBody ClassOrder classOrder) {
        return toAjax(classOrderService.insertClassOrder(classOrder));
    }

    /**
     * 修改课程订单
     */
    @ApiOperation("修改课程订单")
    @PutMapping
    public AjaxResult edit(@RequestBody ClassOrder classOrder) {
        return toAjax(classOrderService.updateClassOrder(classOrder));
    }

    /**
     * 删除课程订单
     */
    @ApiOperation("删除课程订单")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(classOrderService.deleteClassOrderByIds(ids));
    }

    /**
     * 查询待审核取消课程订单
     */
    @ApiOperation("查询待审核取消课程订单")
    @GetMapping("/cancelList")
    public TableDataInfo<ClassOrderVo> cancelList(ClassOrder classOrder) {
        classOrder.setPayStatus(PayStatus.REFUND_TO_AUDIT.getValue());
        startPage();
        List<ClassOrderVo> list = classOrderService.selectClassOrderList(classOrder);
        return getDataTable(list);
    }

}
